package com.silence.springboot.convert;

import com.mybatisflex.core.paginate.Page;
import com.silence.springboot.entity.DailyHealthInfoEntity;
import com.silence.springboot.enums.ContactScreeningEnum;
import com.silence.springboot.enums.SexEnum;
import com.silence.springboot.vo.input.SaveDailyHealthInfoInput;
import com.silence.springboot.vo.output.PageDailyHealthInfoOutput;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

/**
 * @author silence
 * @email 792245022@qq.com
 */
@Mapper(componentModel = "spring")
public interface DailyHealthInfoConvert {


    /**
     * 条件查询每日健康出参转换
     *
     * @param entity 实体
     * @return 出参
     */
    @Mapping(source = "sex", target = "sexText", qualifiedByName = "sexEnumToString")
    @Mapping(source = "contactScreening", target = "contactScreeningText", qualifiedByName = "contactScreeningEnumToString")
    @Mapping(source = "fillDate", target = "fillDate", dateFormat = "yyyy-MM-dd HH:mm:ss")
    PageDailyHealthInfoOutput toPageDailyHealthInfoOutput(DailyHealthInfoEntity entity);

    /**
     * 条件查询每日健康出参转换
     *
     * @param page 入参
     * @return 出参
     */
    Page<PageDailyHealthInfoOutput> convertPageDailyHealthInfoOutput(Page<DailyHealthInfoEntity> page);

    /**
     * 性别枚举转换为字符串
     *
     * @param sex 性别枚举
     * @return 性别字符串
     */
    @Named(value = "sexEnumToString")
    default String sexEnumToString(String sex) {
        try {
            int sexCode = Integer.parseInt(sex);
            return SexEnum.getDescByCode(sexCode);
        } catch (Exception e) {
            return "";
        }
    }

    @Mapping(source = "fillDate", target = "fillDate", dateFormat = "yyyy-MM-dd HH:mm:ss")
    DailyHealthInfoEntity convertDailyHealthInfoEntity(SaveDailyHealthInfoInput input);

    /**
     * 转换接触筛查枚举为字符串
     *
     * @param item 接触筛查枚举
     * @return 接触筛查字符串
     */
    @Named(value = "contactScreeningEnumToString")
    default String contactScreeningEnumToString(String item) {
        try {
            int contactScreeningCode = Integer.parseInt(item);
            return ContactScreeningEnum.getDescByCode(contactScreeningCode);
        } catch (Exception e) {
            return "";
        }
    }

}
